package com.edu.base.ums.student.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.edu.base.ums.student.domain.ClsMemberStudent;
import com.edu.base.ums.student.service.IClsMemberStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生档案Controller
 * 
 * @author lzs
 * @date 2021-05-24
 */
@RestController
@RequestMapping("/cls/student")
public class ClsMemberStudentController extends BaseController
{
    @Autowired
    private IClsMemberStudentService clsMemberStudentService;

    /**
     * 查询学生档案列表
     */
    @PreAuthorize("@ss.hasPermi('cls:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClsMemberStudent clsMemberStudent)
    {
        startPage();
        List<ClsMemberStudent> list = clsMemberStudentService.selectClsMemberStudentList(clsMemberStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生档案列表
     */
    @PreAuthorize("@ss.hasPermi('cls:student:export')")
    @Log(title = "学生档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ClsMemberStudent clsMemberStudent)
    {
        List<ClsMemberStudent> list = clsMemberStudentService.selectClsMemberStudentList(clsMemberStudent);
        ExcelUtil<ClsMemberStudent> util = new ExcelUtil<ClsMemberStudent>(ClsMemberStudent.class);
        return util.exportExcel(list, "student");
    }

    /**
     * 获取学生档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('cls:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(clsMemberStudentService.selectClsMemberStudentById(id));
    }

    /**
     * 新增学生档案
     */
    @PreAuthorize("@ss.hasPermi('cls:student:add')")
    @Log(title = "学生档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClsMemberStudent clsMemberStudent)
    {
        return toAjax(clsMemberStudentService.insertClsMemberStudent(clsMemberStudent));
    }

    /**
     * 修改学生档案
     */
    @PreAuthorize("@ss.hasPermi('cls:student:edit')")
    @Log(title = "学生档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClsMemberStudent clsMemberStudent)
    {
        return toAjax(clsMemberStudentService.updateClsMemberStudent(clsMemberStudent));
    }

    /**
     * 删除学生档案
     */
    @PreAuthorize("@ss.hasPermi('cls:student:remove')")
    @Log(title = "学生档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(clsMemberStudentService.deleteClsMemberStudentByIds(ids));
    }
    
    /**
     * 通过会员ID获取学生档案
     */
    @PreAuthorize("@ss.hasPermi('cls:student:query')")
    @GetMapping(value = "/getClsMemberStudentByMemberId/{id}")
    public AjaxResult getClsMemberStudentByMemberId(@PathVariable("id") String id)
    {
        return AjaxResult.success(clsMemberStudentService.selectClsMemberStudentByMemberId(id));
    }
}
